package com.epidemic.project.system.tongzhi.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.epidemic.project.system.tongzhi.domain.SysTongZhi;
import com.epidemic.project.system.tongzhi.service.ISysTongZhiService;
import com.epidemic.framework.web.controller.BaseController;
import org.springframework.stereotype.Controller;
import com.epidemic.framework.web.domain.AjaxResult;
import com.epidemic.common.utils.poi.ExcelUtil;
import com.epidemic.framework.web.page.TableDataInfo;

/**
 * 通知Controller
 *
 * @author sys
 * @date 2023-02-01
 */
@Controller
@RequestMapping("/system/tongzhi")
public class SysTongZhiController extends BaseController {
    private String prefix = "system/tongzhi";

    @Autowired
    private ISysTongZhiService sysTongZhiService;

    @GetMapping()
    public String tongzhi() {
        return prefix + "/tongzhi";
    }

    /**
     * 查询通知列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysTongZhi sysTongZhi) {
        startPage();
        List<SysTongZhi> list = sysTongZhiService.selectSysTongZhiList(sysTongZhi);
        return getDataTable(list);
    }

    /**
     * 导出通知列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysTongZhi sysTongZhi) {
        List<SysTongZhi> list = sysTongZhiService.selectSysTongZhiList(sysTongZhi);
        ExcelUtil<SysTongZhi> util = new ExcelUtil<SysTongZhi>(SysTongZhi.class);
        return util.exportExcel(list, "tongzhi");
    }

    /**
     * 新增通知
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存通知
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysTongZhi sysTongZhi) {
        return toAjax(sysTongZhiService.insertSysTongZhi(sysTongZhi));
    }

    /**
     * 修改通知
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SysTongZhi sysTongZhi = sysTongZhiService.selectSysTongZhiById(id);
        mmap.put("sysTongZhi", sysTongZhi);
        return prefix + "/edit";
    }

    /**
     * 修改保存通知
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysTongZhi sysTongZhi) {
        return toAjax(sysTongZhiService.updateSysTongZhi(sysTongZhi));
    }

    /**
     * 删除通知
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysTongZhiService.deleteSysTongZhiByIds(ids));
    }
}
